package acm.pta9;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.HashSet;
    import java.util.Set;
    import java.util.StringTokenizer;

    public class 深入虎穴 {
        static int[][] map;
        static boolean visited[];
        //返回该节点最远抵达的子孩子编号，和距离
        public static int[] fun(int i){
            if (visited[i]){
                return new int[]{i,-1};
            }
            if (map[i].length==0){  //叶子节点
                return new int[]{i,0};
            }
            visited[i]=true;
            int[] res={i,0};
            for (int j = 0; j < map[i].length; j++) {
                int[] fun = fun(map[i][j]);
                if (fun[1]+1>res[1]){   //更新最远距离
                    res[0]=fun[0];
                    res[1]=fun[1]+1;
                }
            }
            visited[i]=false;
            return res;
        }
        public static void main(String[] args) {
            Reader sc=new Reader();
            int n = sc.nextInt();
            map=new int[n+1][];
            visited=new boolean[n+1];
            Set<Integer> set=new HashSet<>();
            for (int i = 1; i <= n; i++) {
                set.add(i);
            }
            for (int i = 1; i < map.length; i++) {
                map[i]=new int[sc.nextInt()];
                for (int j = 0; j < map[i].length; j++) {
                    int to = sc.nextInt();
                    map[i][j]=to;
                    set.remove(to);
                }
            }
            int[] res=fun(set.iterator().next());
            System.out.println(res[0]);
        }
        static class Reader {
            private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            private StringTokenizer tokenizer = new StringTokenizer("");

            private String innerNextLine() {
                try {
                    return reader.readLine();
                } catch (IOException ex) {
                    return null;
                }
            }

            public boolean hasNext() {
                while (!tokenizer.hasMoreTokens()) {    //内存中没有
                    String nextLine = innerNextLine();
                    if (nextLine == null) {     //且没有下一行
                        return false;
                    }
                    tokenizer = new StringTokenizer(nextLine);  //读入一行
                }
                return true;
            }

            public String nextLine() {
                tokenizer = new StringTokenizer("");    //清空内存中的字符
                return innerNextLine();
            }

            public String next() {
                hasNext();
                return tokenizer.nextToken();
            }

            public int nextInt() {
                return Integer.parseInt(next());
            }

            public long nextLong() {
                return Long.parseLong(next());
            }

            public double nextDouble(){
                return Double.parseDouble(next());
            }
    //    public BigInteger nextBigInt() {
    //        return new BigInteger(next());
    //    }
        }

    }
